/* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements.  See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License.  You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/


/*************************************************************************
 *\author: starlove
 *************************************************************************/
#ifndef __CC_PYTHON_IMPORT_O_EGLVIEW_IMPL__
#define __CC_PYTHON_IMPORT_O_EGLVIEW_IMPL__

#include "python_object_eglview.h"

NS_CCPY_BEGIN
	PYCLASS_INIT_F(CPyEGLView, "sharedOpenGLView", "Python sharedOpenGLView Object");
	PYCLASS_BEGIN_METHOD_DEF(CPyEGLView)
		PYCLASS_ADD_METHOD_EX(CPyEGLView, setFrameSize, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyEGLView, setDesignResolutionSize, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyEGLView, setViewPortInPoints, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyEGLView, setScissorInPoints, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyEGLView, getFrameSize, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyEGLView, getVisibleSize, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyEGLView, getVisibleOrigin, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyEGLView, getDesignResolutionSize, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyEGLView, isScissorEnabled, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyEGLView, getScissorRect, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyEGLView, getViewName, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyEGLView, setViewName, METH_STATIC|METH_VARARGS)
	PYCLASS_END_METHOD_DEF(CPyEGLView)
	PYCLASS_BEGIN_GETSET_DEF(CPyEGLView)
	PYCLASS_END_GETSET_DEF(CPyEGLView)
	PYCLASS_IMP_INTERFACE(CPyEGLView)
	
	PYCLASS_METHOD_IMPL(CPyEGLView, sharedOpenGLView)
	{
		static CPyEGLView *view = NULL;
		if(!view)
		{
			view = PyObject_New(CPyEGLView, CPyClassBase::GetTypeObject<CPyEGLView>());
			Py_XINCREF(view);
		}
		return (PyObject *)view;
	}

	PYCLASS_METHOD_IMPL(CPyEGLView, setFrameSize)
	{		
		float w = 0;
		float h = 0;
		if( !PyArg_ParseTuple(pyArgs, "ff", &w, &h) )
			Py_RETURN_NONE;
		cocos2d::CCEGLView::sharedOpenGLView()->setFrameSize(w, h);
		Py_RETURN_NONE;
	}

	PYCLASS_METHOD_IMPL(CPyEGLView, setDesignResolutionSize)
	{
		float w = 0;
		float h = 0;
		unsigned int resolutionPolicy = 0;
		if( !PyArg_ParseTuple(pyArgs, "ffI", &w, &h, &resolutionPolicy) )
			Py_RETURN_NONE;
		cocos2d::CCEGLView::sharedOpenGLView()->setDesignResolutionSize(w, h, static_cast<ResolutionPolicy>(resolutionPolicy));
		Py_RETURN_NONE;
	}

	PYCLASS_METHOD_IMPL(CPyEGLView, setViewPortInPoints)
	{
		float x = 0;
		float y = 0;
		float w = 0;
		float h = 0;
		if( !PyArg_ParseTuple(pyArgs, "ffff", &x, &y, &w, &h) )
			Py_RETURN_NONE;
		cocos2d::CCEGLView::sharedOpenGLView()->setViewPortInPoints(x, y, w, h);
		Py_RETURN_NONE;
	}

	PYCLASS_METHOD_IMPL(CPyEGLView, setScissorInPoints)
	{
		float x = 0;
		float y = 0;
		float w = 0;
		float h = 0;
		if( !PyArg_ParseTuple(pyArgs, "ffff", &x, &y, &w, &h) )
			Py_RETURN_NONE;
		cocos2d::CCEGLView::sharedOpenGLView()->setScissorInPoints(x, y, w, h);
		Py_RETURN_NONE;
	}
	
	PYCLASS_METHOD_IMPL(CPyEGLView, getFrameSize)
	{
		cocos2d::CCSize si = cocos2d::CCEGLView::sharedOpenGLView()->getFrameSize();
		CPySize *size = CPySize::create(si);
		return (PyObject *)size;
	}

	PYCLASS_METHOD_IMPL(CPyEGLView, getVisibleSize)
	{
		CPySize *size = CPySize::create(cocos2d::CCEGLView::sharedOpenGLView()->getVisibleSize());
		return (PyObject *)size;
	}
	PYCLASS_METHOD_IMPL(CPyEGLView, getVisibleOrigin)
	{
		CPyPoint *pt = CPyPoint::create(cocos2d::CCEGLView::sharedOpenGLView()->getVisibleOrigin());
		return (PyObject *)pt;
	}
	PYCLASS_METHOD_IMPL(CPyEGLView, getDesignResolutionSize)
	{
		cocos2d::CCSize si = cocos2d::CCEGLView::sharedOpenGLView()->getDesignResolutionSize();
		CPySize *size = CPySize::create(si);
		return (PyObject *)size;
	}
	PYCLASS_METHOD_IMPL(CPyEGLView, isScissorEnabled)
	{
		Py_RETURN_BOOL(cocos2d::CCEGLView::sharedOpenGLView()->isScissorEnabled());
	}
	PYCLASS_METHOD_IMPL(CPyEGLView, getScissorRect)
	{
		CPyRect *rt = CPyRect::create(cocos2d::CCEGLView::sharedOpenGLView()->getScissorRect());
		return (PyObject *)rt;
	}
	PYCLASS_METHOD_IMPL(CPyEGLView, getViewName)
	{
		return Py_BuildValue("s", cocos2d::CCEGLView::sharedOpenGLView()->getViewName());
	}
	PYCLASS_METHOD_IMPL(CPyEGLView, setViewName)
	{
		char *s = NULL;
		if( !PyArg_ParseTuple(pyArgs, "s", &s) )
			return 0;
		if(!s)
			return 0;
		cocos2d::CCEGLView::sharedOpenGLView()->setViewName(s);
		return 0;
	}

NS_CCPY_END

#endif